package com.ruoyi.driver.controller;

import java.io.Console;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.driver.domain.CarownerDetials;
import com.ruoyi.driver.service.ICarownerDetialsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车主详情Controller
 * 
 * @author Wevon
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/driver/detials")
public class CarownerDetialsController extends BaseController
{
    @Autowired
    private ICarownerDetialsService carownerDetialsService;

    /**
     * 查询车主详情列表
     */
    @PreAuthorize("@ss.hasPermi('driver:detials:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerDetials carownerDetials)
    {
        startPage();
        List<CarownerDetials> list = carownerDetialsService.selectCarownerDetialsList(carownerDetials);
        System.out.println(getDataTable(list));
        System.out.println("getDataTable(list) = " +list);
        return getDataTable(list);
    }

    /**
     * 导出车主详情列表
     */
    @PreAuthorize("@ss.hasPermi('driver:detials:export')")
    @Log(title = "车主详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerDetials carownerDetials)
    {
        List<CarownerDetials> list = carownerDetialsService.selectCarownerDetialsList(carownerDetials);
        ExcelUtil<CarownerDetials> util = new ExcelUtil<CarownerDetials>(CarownerDetials.class);
        util.exportExcel(response, list, "车主详情数据");
    }

    /**
     * 获取车主详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('driver:detials:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carownerDetialsService.selectCarownerDetialsById(id));
    }

    /*根据手机号获取车主信息*/
    @GetMapping(value = "/phone/{phone}")
    public AjaxResult selectCarOwnerDetailsByPhone(@PathVariable("phone") String phone){
        System.out.println("carownerDetialsService.selectCarOwnerDetailsByPhone(phone) = " + carownerDetialsService.selectCarOwnerDetailsByPhone(phone));
        return success(carownerDetialsService.selectCarOwnerDetailsByPhone(phone));
    }

    /**
     * 新增车主详情
     */
    @PreAuthorize("@ss.hasPermi('driver:detials:add')")
    @Log(title = "车主详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerDetials carownerDetials)
    {
        return toAjax(carownerDetialsService.insertCarownerDetials(carownerDetials));
    }

    /**
     * 修改车主详情
     */
    @PreAuthorize("@ss.hasPermi('driver:detials:edit')")
    @Log(title = "车主详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerDetials carownerDetials)
    {
        return toAjax(carownerDetialsService.updateCarownerDetials(carownerDetials));
    }

    /**
     * 删除车主详情
     */
    @PreAuthorize("@ss.hasPermi('driver:detials:remove')")
    @Log(title = "车主详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carownerDetialsService.deleteCarownerDetialsByIds(ids));
    }
}
